package com.freesun.monitor.ld;

import com.freesun.monitor.db.OperateMariaDb;
//import lrapi.lr;

import java.sql.ResultSet;

/**
 * Created by yangfei on 13-12-6.
 */
public class OneDbInsertMonitor {

    private OperateMariaDb operateMariaDb;
    private String idt = "insert into test01(name,pass,remark,created_at,updated_at) values('yangfei11','i','验证ondb',now(),now())";


    /**
     * @desc 初始化连接数据库
     * @return
     * @throws Throwable
     */
    public int init() throws Throwable{
        operateMariaDb = new OperateMariaDb();
        operateMariaDb.GetConnect("jdbc:mysql://192.168.1.67:3306/onedb", "root", "123456");
//        lr.message("建立连接:jdbc:mysql://192.168.1.67:3306/onedb 成功!");
        return 0;
    }

    /**
     * @desc 可以执行多次，可以进行参数操作
     * @return
     * @throws Throwable
     */
    public int action() throws Throwable{
        int bl = operateMariaDb.InsertData(idt);
        if (bl>0){
//            lr.message("插入sql:"+idt+"成功!");
        }else {
//            lr.error_message("插入sql:" + idt + "失败!");
        }
        return 0;
    }

    /**
     * @desc 销毁数据只执行一次
     * @return
     * @throws Throwable
     */
    public int end() throws Throwable{
        operateMariaDb.ConnectClose();
//        lr.message("关闭连接:jdbc:mysql://192.168.1.67:3306/onedb 成功!");
        return 0;
    }
}
